package com.meicet.adapter.dialog

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import androidx.annotation.Keep
import com.lxj.xpopup.core.CenterPopupView
import com.lxj.xpopup.util.XPopupUtils
import com.meicet.adapter.R

/**
 * 可以设置dialog到任意位置
 */
@Keep
abstract class DialogBase(
    context: Context,
    private val layoutID: Int,
    private val gravity: Int = Gravity.CENTER
) : CenterPopupView(context) {

    override fun addInnerContent() {
        val view = LayoutInflater.from(context).inflate(layoutID, centerPopupContainer, false)
        val param = view.layoutParams as LayoutParams
        param.gravity = gravity
        centerPopupContainer.addView(view, param)
    }

    override fun getImplLayoutId() = R.layout._dialog_base_popup_view
    override fun getMaxWidth(): Int {
        return if (popupInfo.maxWidth == 0) (XPopupUtils.getAppWidth(context)) else popupInfo.maxWidth
    }
}
